//------------------------------------------------------------------------------
//  Resource.cpp
//  (C) 2010 xoyojank
//------------------------------------------------------------------------------
#include "StdEddy.h"
#include "Graphics/Resource.h"
#include "Graphics/ResourceLoader.h"
#include "Graphics/ResourceSaver.h"

//------------------------------------------------------------------------------
namespace Eddy
{

//------------------------------------------------------------------------------
Resource::Resource()
    : loader(NULL)
    , saver(NULL)
    , isLoaded(false)
{
    // empty
}

//------------------------------------------------------------------------------
Resource::~Resource()
{
    // empty
}

//------------------------------------------------------------------------------
bool
Resource::Load()
{
    assert(NULL != this->loader);
    assert(!this->IsLoaded());

    this->isLoaded = this->loader->OnLoad();
    this->loader = NULL;

    return this->isLoaded;
}

//------------------------------------------------------------------------------
bool
Resource::Save()
{
    assert(NULL != this->saver);
    assert(this->IsLoaded());

    bool result = this->saver->OnSave();
    this->saver = NULL;

    return result;
}

//------------------------------------------------------------------------------
void
Resource::SetLoader(ResourceLoader* l)
{
    assert(NULL != l);
    assert(NULL == this->loader);

    this->loader = l;
    this->loader->OnAttachResource(this);
}

//------------------------------------------------------------------------------
void
Resource::SetSaver(ResourceSaver* s)
{
    assert(NULL != s);
    assert(NULL == this->saver);

    this->saver = s;
    this->saver->OnAttachResource(this);
}

}// Eddy
